package com.fourGirlsAndADude.mobileDRT;

import java.io.File;
import java.util.ArrayList;

import com.att.intern.webservice.Incident;
import com.att.intern.webservice.Webservice;
import com.att.intern.webservice.Webservice.GeolocInvalidException;
import com.att.intern.webservice.Webservice.TokenInvalidException;



import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

/**
 * Update Assessment class
 * Handles updating properties of existing incidents
 * @author sg101v
 *
 */
public class UpdateAssementActivity extends Activity {
	
	/*All the variables for the fields*/
	static Incident aIncident;
	TextView RecordId, CRELead, Event, EventYear, State, PM, GLC, PropertyType, 
	Building, Address, Requestor, ContactNumber, InitialReportDate, 
	Electrical, Grounds, Plumbing, Environmental, Mechanical, Roofs, FenceGates, 
	Other, Safety, Generator, Structural, Water, WorkReqNumber;
	
	EditText requesterIDedit, contactNum, initialRptDate, workReqNum;
	Spinner eventYear, eventName, propType;
	// Group 2: NON-CO Facility, group of editable fields 2 Drop Boxes 
	Spinner commercialPower, onGenerator;
	// Group 3: Any Facility, group of editable fields 5 drop boxes    
	Spinner damage, mobCo, unoccupiable, buildingStatus, creLead;
	//Group 4: Estimated Costs group of editable fields 2 EditText fields 
	EditText capital, expense;
	//Group 5: catagories group of editable fields drop boxes    	 
	Spinner elecIssue, elecClosed, envirIssue, envirClosed, 
		fgIssue, fgClosed, genIssue, genClosed, waterIssue, waterClosed, groundsIssue,
		groundsClosed, mechIssue, mechClosed, otherIssue, otherClosed, plumbIssue, plumClosed,
		roofIssue, roofClosed, safeIssue, safeClosed, structIssue, structClosed;
	//Group 6: last fields group of editable fields 4 EditTexts, 1 DropBox 
	EditText assessment, status, compDate, notes;
	Spinner rep_OC;
	
	Button addPictureTop, saveTop, cancelTop, cancelBottom, saveBottom, addPictureBottom;
	
	// Adapters for spinners
	private ArrayAdapter<String> yearAdapter;
	private ArrayAdapter<String> nameAdapter;

	// ArrayList for spinners
	private ArrayList<String> yearArrayList = new ArrayList<String>();
	private ArrayList<String> nameArrayList = new ArrayList<String>();

	private int yearSelected;
	private String nameSelected;
	private String reportStatusSelected;
	private String propertyTypeSelected;
	private String commercialPowerSelected;
	private String onGeneratorSelected;
	private String damageSelected, mobCoSelected, unoccupiableSelected, buildingStatusSelected;
	private String elecIssueSelected, elecClosedSelected, envirIssueSelected, envirClosedSelected, 
	fgIssueSelected, fgClosedSelected, genIssueSelected, genClosedSelected, waterIssueSelected, waterClosedSelected, groundsIssueSelected,
	groundsClosedSelected, mechIssueSelected, mechClosedSelected, otherIssueSelected, otherClosedSelected, plumbIssueSelected, plumbClosedSelected,
	roofIssueSelected, roofClosedSelected, safetyIssueSelected, safetyClosedSelected, structIssueSelected, structClosedSelected;
	
	ImageView update;
	
	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_update_assement);
		
		aIncident = (Incident)this.getIntent().getExtras().get("INCIDENT");
		Log.d("UpdateAssessment", "Got the incident in Update Screen!");
		Context context2 = getApplicationContext();
    	final Webservice test = new Webservice(context2);
		final Toast success = Toast.makeText(context2, "Updated!", Toast.LENGTH_SHORT);
    	final Toast fail1 = Toast.makeText(context2, "Fail!", Toast.LENGTH_SHORT);
    	final Toast fail2= Toast.makeText(context2, "No!", Toast.LENGTH_SHORT);
    	final String sessionTokenId = this.getIntent().getStringExtra("SESSION");
	    final String userNameStr = this.getIntent().getStringExtra("USER");
		final String authorizationType = this.getIntent().getStringExtra("AUTHTYPE");
		//Picture
		final String picture = this.getIntent().getStringExtra("PictureFile");
		File displayPic = new File(picture);
		if(displayPic.exists()){
			Bitmap myBitmap = BitmapFactory.decodeFile(displayPic.getAbsolutePath());
			update =(ImageView)findViewById(R.id.imageView1);
		    update.setImageBitmap(myBitmap);

		}
//TextViews start
		final int recordNum = this.getIntent().getIntExtra("RECORDID", 0);
		Log.d("UpdateAssessment", "Record number: "+recordNum);
		RecordId=(TextView)findViewById(R.id.recordId);
		RecordId.setText("Record Id: " +recordNum);
		CRELead=(TextView)findViewById(R.id.creLeadPrepopulated);
		CRELead.setText("CRELead: " +aIncident.getCreLead());
		Log.d("Update", "Crelead: "+aIncident.getCreLead());
		Event=(TextView)findViewById(R.id.event);
		Event.setText("Event:" + aIncident.getEventName());
		Log.d("Update", "Event: "+aIncident.getEventName());
		EventYear=(TextView)findViewById(R.id.eventYearPrepopulated);
		EventYear.setText("Event Year: "+aIncident.getIncidentYear());
		Log.d("Update", "Event Year: "+aIncident.getIncidentYear());
		State=(TextView)findViewById(R.id.state);
		State.setText("State: " +aIncident.getState());
		Log.d("Update", "State: "+aIncident.getState());
		PM=(TextView)findViewById(R.id.pm);
		PM.setText("PM: "+aIncident.getPMAttuid());
		Log.d("Update", "PM: "+aIncident.getPMAttuid());
		GLC=(TextView)findViewById(R.id.glc);
		GLC.setText("GLC: "+aIncident.getGeoLoc());
		Log.d("Update", "GLC: "+aIncident.getGeoLoc());
		PropertyType=(TextView)findViewById(R.id.propertType);
		PropertyType.setText("Property Type: "+aIncident.getBuildingType());
		Log.d("update", "Property Type: "+aIncident.getBuildingType());
		Building=(TextView)findViewById(R.id.building);
		Building.setText("Building: " +aIncident.getBuildingName());
		Log.d("Update", "Building: " +aIncident.getBuildingName());
		Address=(TextView)findViewById(R.id.address);
		Address.setText("Address: " +aIncident.getBuildingAddress());
		Log.d("Update", "Address: " +aIncident.getBuildingAddress());
		Requestor=(TextView)findViewById(R.id.requestor);
		Requestor.setText("Requestor: " +aIncident.getReqATTUID());
		Log.d("Update", "Requestor: " +aIncident.getReqATTUID());
		ContactNumber=(TextView)findViewById(R.id.contactNumber);
		ContactNumber.setText("ContactNumber: " +aIncident.getContactPhone());
		Log.d("Update", "ContactNumber: " +aIncident.getContactPhone());
		InitialReportDate=(TextView)findViewById(R.id.intialReportDate);
		InitialReportDate.setText("InitialReportDate: " +aIncident.getInitialRptDate());
		Log.d("Update", "InitialReportDate: " +aIncident.getInitialRptDate());
		Electrical=(TextView)findViewById(R.id.electrical);
		Electrical.setText("Electrical: " +aIncident.getElecIssueIndicator());
		Log.d("Update", "Electrical: " +aIncident.getElecIssueIndicator());
		Grounds=(TextView)findViewById(R.id.grounds);
		Grounds.setText("Grounds: " +aIncident.getGroundsIssueIndicator());
		Log.d("Update", "Grounds: " +aIncident.getGroundsIssueIndicator());
		Plumbing=(TextView)findViewById(R.id.plumbing);
		Plumbing.setText("Plumbing: " +aIncident.getPlumbIssueIndicator());
		Log.d("Update", "Plumbing: " +aIncident.getPlumbIssueIndicator());
		Environmental=(TextView)findViewById(R.id.environmental);
		Environmental.setText("Environmental: " +aIncident.getEnvIssueIndicator());
		Log.d("Update", "Environmental: " +aIncident.getEnvIssueIndicator());
		Mechanical=(TextView)findViewById(R.id.mechanical);
		Mechanical.setText("Mechanical: " +aIncident.getMechIssueIndicator());
		Log.d("Update", "Mechanical: " +aIncident.getMechIssueIndicator());
		Roofs=(TextView)findViewById(R.id.roofs);
		Roofs.setText("Roofs: " +aIncident.getRoofsIssueIndicator());
		Log.d("Update", "Roofs: " +aIncident.getRoofsIssueIndicator());
		FenceGates=(TextView)findViewById(R.id.fenceOrGates);
		FenceGates.setText("FenceGates: " +aIncident.getFenceGateIssueIndicator());
		Log.d("Update", "FenceGates: " +aIncident.getFenceGateIssueIndicator());
		Other=(TextView)findViewById(R.id.other);
		Other.setText("Other: " +aIncident.getOtherIssueIndicator());
		Log.d("Update", "Other: " +aIncident.getOtherIssueIndicator());
		Safety=(TextView)findViewById(R.id.safety);
		Safety.setText("Safety: " +aIncident.getSafetyIssueIndicator());
		Log.d("Update", "Safety: " +aIncident.getSafetyIssueIndicator());
		Generator=(TextView)findViewById(R.id.generator);
		Generator.setText("Generator: " +aIncident.getGenIssueIndicator());
		Log.d("Update", "Generator: " +aIncident.getGenIssueIndicator());
		Structural=(TextView)findViewById(R.id.structural);
		Structural.setText("Structural: " +aIncident.getStructIssueIndicator());
		Log.d("Update", "Structural: " +aIncident.getStructIssueIndicator());
		Water=(TextView)findViewById(R.id.water);
		Water.setText("Water: " +aIncident.getWaterIssueIndicator());
		Log.d("Update", "Water: " +aIncident.getWaterIssueIndicator());
		WorkReqNumber=(TextView)findViewById(R.id.workRequestNumber);
		WorkReqNumber.setText("WorkReqNumber: " +aIncident.getWorkReqNumber());
		Log.d("Update", "WorkReqNumber: " +aIncident.getWorkReqNumber());
//TextViews end
		
//Edit Texts start
		assessment =(EditText)findViewById(R.id.assessment);
		assessment.setText(aIncident.getAssessNotes(), TextView.BufferType.EDITABLE);
		Log.d("Update", "Assesment: "+aIncident.getAssessNotes());
		status=(EditText)findViewById(R.id.status);
		status.setText(aIncident.getStatusNotes(), TextView.BufferType.EDITABLE);
		Log.d("Update", "Status: "+aIncident.getStatusNotes());
		compDate =(EditText)findViewById(R.id.completionDate);
		compDate.setText(aIncident.getCompltnDate(), TextView.BufferType.EDITABLE);
		Log.d("Update", "Compdate: "+aIncident.getCompltnDate());
		notes =(EditText)findViewById(R.id.notes);
		notes.setText(aIncident.getIncidentNotes(), TextView.BufferType.EDITABLE);
		Log.d("Update","Notes: "+aIncident.getIncidentNotes());
		capital =(EditText)findViewById(R.id.capital);
		capital.setText(Integer.toString(aIncident.getEstCapCost()), TextView.BufferType.EDITABLE);
		Log.d("Update", "Capital: "+aIncident.getEstCapCost());
		expense=(EditText)findViewById(R.id.expense);
		expense.setText(Integer.toString(aIncident.getEstExpenseCost()), TextView.BufferType.EDITABLE);	
		Log.d("Update", "Expense: "+aIncident.getEstExpenseCost());
//Edit texts end
		
//Spinner start		
		rep_OC=(Spinner)findViewById(R.id.reportO_C);
		//rep_OC.setSelection(0); //present to open
		Log.d("Update", "Report status: "+aIncident.getIncidentStatus());
		reportStatusSelected = aIncident.getIncidentStatus();
		if(reportStatusSelected.equals("Open")){
			rep_OC.setSelection(0);
		}
		else{
			rep_OC.setSelection(1);
		}
    	rep_OC.setOnItemSelectedListener(new ReportOpenOnItemSelectedListener());
    	
    	commercialPower=(Spinner)findViewById(R.id.commercialPower);
    	Log.d("Update on create", "CommercialPower: "+aIncident.getComPowerIndicator());
    	commercialPowerSelected=aIncident.getComPowerIndicator();
    	if(commercialPowerSelected.equals("Y")){
        	commercialPower.setSelection(0);

    	}
    	else{
    		commercialPower.setSelection(1);
    	}
		//commercialPower.setOnItemSelectedListener(new CommercialPowerOnSelectedItemClickListener());
		
		onGenerator = (Spinner)findViewById(R.id.onGeneratorSpinner);
		Log.d("Update on create", "onGenerator: "+aIncident.getOnGeneratorIndicator());
		onGeneratorSelected = aIncident.getOnGeneratorIndicator();
		if(onGeneratorSelected.equals("Y")){
			onGenerator.setSelection(0);

    	}
    	else{
    		onGenerator.setSelection(1);
    	}
		//onGenerator.setOnItemSelectedListener(new onGeneratorOnItemSelectedListener());
		
		damage = (Spinner)findViewById(R.id.damaged);
		Log.d("Update", "damage: "+aIncident.getDamageIndicator());
		damageSelected = aIncident.getDamageIndicator();
		if(damageSelected.equals("N")){
			damage.setSelection(0);

    	}
    	else{
    		damage.setSelection(1);
    	}
		damage.setOnItemSelectedListener(new DamagedOnItemSelectedListener());
		
		mobCo=(Spinner)findViewById(R.id.mobilityCO);
		Log.d("Update", "mobCo: "+aIncident.getMobCOIndicator());
		mobCoSelected = aIncident.getMobCOIndicator();
		if(mobCoSelected.equals("N")){
			mobCo.setSelection(0);

    	}
    	else{
    		mobCo.setSelection(1);
    	}
		mobCo.setOnItemSelectedListener(new mobCoOnItemSelectedListener());

		unoccupiable=(Spinner)findViewById(R.id.unoccupiable);
		Log.d("Update", "unoccupiable: "+aIncident.getUnOccupiableIndicator());
		unoccupiableSelected =aIncident.getUnOccupiableIndicator();
		if(unoccupiableSelected.equals("N")){
			unoccupiable.setSelection(0);
		}
		else{
			unoccupiable.setSelection(1);
		}
        unoccupiable.setOnItemSelectedListener(new unoccupiableOnItemSelectedListener());

		buildingStatus=(Spinner)findViewById(R.id.buildingStatus);
		Log.d("Update", "buildingStatus: "+aIncident.getBuildingStatus());
		buildingStatusSelected =aIncident.getBuildingStatus();
		if(buildingStatusSelected.equals("OPEN")){
			buildingStatus.setSelection(0);
		}
		else if(buildingStatusSelected.equals("CLOSED")){
			buildingStatus.setSelection(1);
		}
		else if (buildingStatusSelected.equals("DELAYED")){
			buildingStatus.setSelection(2);
		}
		else if(buildingStatusSelected.equals("OPENING")){
			buildingStatus.setSelection(3);
		}
		else{
			buildingStatus.setSelection(4);
		}
        buildingStatus.setOnItemSelectedListener(new buildingStatusOnItemSelectedListener());

		
		elecIssue=(Spinner)findViewById(R.id.issueElectric);
		Log.d("Update", "elecIssue: "+aIncident.getElecIssueIndicator());
		elecIssueSelected =aIncident.getElecIssueIndicator();
		if(elecIssueSelected.equals("N")){
			elecIssue.setSelection(0);
		}
		else{
			elecIssue.setSelection(1);
			elecIssue.setEnabled(false);
		}
        elecIssue.setOnItemSelectedListener(new elecIssueOnItemSelectedListener());

		
		elecClosed = (Spinner)findViewById(R.id.closedElectric);
		Log.d("Update", "elecIssue: "+aIncident.getElecIssueClsdIndicator());
		elecClosedSelected =aIncident.getElecIssueClsdIndicator();
		if(elecClosedSelected.equals("N")){
			elecClosed.setSelection(0);
		}
		else{
			elecClosed.setSelection(1);
		}
        elecClosed.setOnItemSelectedListener(new elecClosedOnItemSelectedListener());

		
		envirIssue = (Spinner)findViewById(R.id.issueEnviron);
		Log.d("Update", "envirIssue: "+aIncident.getEnvIssueIndicator());
		envirIssueSelected =aIncident.getEnvIssueIndicator();
		if(envirIssueSelected.equals("N")){
			envirIssue.setSelection(0);
		}
		else{
			envirIssue.setSelection(1);
			envirIssue.setEnabled(false);
		}
        envirIssue.setOnItemSelectedListener(new envirIssueOnItemSelectedListener());

		
		envirClosed = (Spinner)findViewById(R.id.closedEnviron);
		Log.d("Update", "envirClosed: "+aIncident.getEnvIssueClsdIndicator());
		envirClosedSelected =aIncident.getEnvIssueClsdIndicator();
		if(envirClosedSelected.equals("N")){
			envirClosed.setSelection(0);
		}
		else{
			envirClosed.setSelection(1);
		}
        envirClosed.setOnItemSelectedListener(new envirClosedOnItemSelectedListener());

		
		fgIssue = (Spinner)findViewById(R.id.issueFence);
		Log.d("Update", "fgIssue: "+aIncident.getFenceGateIssueIndicator());
		fgIssueSelected =aIncident.getFenceGateIssueIndicator();
		if(fgIssueSelected.equals("N")){
			fgIssue.setSelection(0);
		}
		else{
			fgIssue.setSelection(1);
			fgIssue.setEnabled(false);
		}
        fgIssue.setOnItemSelectedListener(new fgIssueOnItemSelectedListener());

		
		fgClosed = (Spinner)findViewById(R.id.closedFence);
		Log.d("Update", "fgClosed: "+aIncident.getFenceGateIssueClsdIndicator());
		fgClosedSelected =aIncident.getFenceGateIssueClsdIndicator();
		if(fgClosedSelected.equals("N")){
			fgClosed.setSelection(0);
		}
		else{
			fgClosed.setSelection(1);
		}
        fgClosed.setOnItemSelectedListener(new fgClosedOnItemSelectedListener());

		genIssue = (Spinner)findViewById(R.id.issueGen);
		Log.d("Update", "genIssue: "+aIncident.getGenIssueIndicator());
		genIssueSelected =aIncident.getGenIssueIndicator();
		if(genIssueSelected.equals("N")){
			genIssue.setSelection(0);
		}
		else{
			genIssue.setSelection(1);
			genIssue.setEnabled(false);
		}
        genIssue.setOnItemSelectedListener(new genIssueOnItemSelectedListener());

		
		genClosed = (Spinner)findViewById(R.id.closedGen);
		Log.d("Update", "genClosed: "+aIncident.getGenIssueClsdIndicator());
		genClosedSelected =aIncident.getGenIssueClsdIndicator();
		if(genClosedSelected.equals("N")){
			genClosed.setSelection(0);
		}
		else{
			genClosed.setSelection(1);
			
		}
        genClosed.setOnItemSelectedListener(new genClosedOnItemSelectedListener());

		
		waterIssue = (Spinner)findViewById(R.id.issueWater);
		Log.d("Update", "waterIssue: "+aIncident.getWaterIssueIndicator());
		waterIssueSelected =aIncident.getWaterIssueIndicator();
		if(waterIssueSelected.equals("N")){
			waterIssue.setSelection(0);
		}
		else{
			waterIssue.setSelection(1);
			waterIssue.setEnabled(false);
			
		}
        waterIssue.setOnItemSelectedListener(new waterIssueOnItemSelectedListener());

		
		waterClosed = (Spinner)findViewById(R.id.closedWater);
		Log.d("Update", "waterClosed: "+aIncident.getWaterIssueClsdIndicator());
		waterClosedSelected =aIncident.getWaterIssueClsdIndicator();
		if(waterClosedSelected.equals("N")){
			waterClosed.setSelection(0);
		}
		else{
			waterClosed.setSelection(1);
			
		}
        waterClosed.setOnItemSelectedListener(new waterClosedOnItemSelectedListener());

		
		groundsIssue=(Spinner)findViewById(R.id.issueGround);
		Log.d("Update", "groundsIssue: "+aIncident.getGroundsIssueIndicator());
		groundsIssueSelected =aIncident.getGroundsIssueIndicator();
		if(groundsIssueSelected.equals("N")){
			groundsIssue.setSelection(0);
		}
		else{
			groundsIssue.setSelection(1);
			groundsIssue.setEnabled(false);
			
		}
        groundsIssue.setOnItemSelectedListener(new groundsIssueOnItemSelectedListener());

		
		groundsClosed=(Spinner)findViewById(R.id.closedGround);
		Log.d("Update", "groundsClosed: "+aIncident.getGroundsIssueClsdIndicator());
		groundsClosedSelected =aIncident.getGroundsIssueClsdIndicator();
		if(groundsClosedSelected.equals("N")){
			groundsClosed.setSelection(0);
		}
		else{
			groundsClosed.setSelection(1);
			
		}
        groundsClosed.setOnItemSelectedListener(new groundsClosedOnItemSelectedListener());

		
		mechIssue = (Spinner)findViewById(R.id.issueMech);
		Log.d("Update", "mechIssue: "+aIncident.getMechIssueIndicator());
		mechIssueSelected =aIncident.getMechIssueIndicator();
		if(mechIssueSelected.equals("N")){
			mechIssue.setSelection(0);
		}
		else{
			mechIssue.setSelection(1);
			mechIssue.setEnabled(false);
			
		}
        mechIssue.setOnItemSelectedListener(new mechIssueOnItemSelectedListener());

		
		mechClosed = (Spinner)findViewById(R.id.closedMech);
		Log.d("Update", "mechClosed: "+aIncident.getMechIssueClsdIndicator());
		mechClosedSelected =aIncident.getMechIssueClsdIndicator();
		if(mechClosedSelected.equals("N")){
			mechClosed.setSelection(0);
		}
		else{
			mechClosed.setSelection(1);
			
		}
        mechClosed.setOnItemSelectedListener(new mechClosedOnItemSelectedListener());

		
		otherIssue=(Spinner)findViewById(R.id.issueOther); 
		Log.d("Update", "otherIssue: "+aIncident.getOtherIssueIndicator());
		otherIssueSelected =aIncident.getOtherIssueIndicator();
		if(otherIssueSelected.equals("N")){
			otherIssue.setSelection(0);
		}
		else{
			otherIssue.setSelection(1);
			otherIssue.setEnabled(false);
			
		}
        otherIssue.setOnItemSelectedListener(new otherIssueOnItemSelectedListener());

		
		otherClosed = (Spinner)findViewById(R.id.closedOther);
		Log.d("Update", "otherClosed: "+aIncident.getOtherIssueClsdIndicator());
		otherClosedSelected =aIncident.getOtherIssueClsdIndicator();
		if(otherClosedSelected.equals("N")){
			otherClosed.setSelection(0);
		}
		else{
			otherClosed.setSelection(1);
			
		}
        otherClosed.setOnItemSelectedListener(new otherClosedOnItemSelectedListener());

        
		plumbIssue = (Spinner)findViewById(R.id.issuePlumb);
		Log.d("Update", "plumbIssue: "+aIncident.getPlumbIssueIndicator());
		plumbIssueSelected =aIncident.getPlumbIssueIndicator();
		if(plumbIssueSelected.equals("N")){
			plumbIssue.setSelection(0);
		}
		else{
			plumbIssue.setSelection(1);
			plumbIssue.setEnabled(false);
			
		}
        plumbIssue.setOnItemSelectedListener(new plumbIssueOnItemSelectedListener());

		
		plumClosed=(Spinner)findViewById(R.id.closedPlumb);
		Log.d("Update", "plumClosed: "+aIncident.getPlumbIssueClsdIndicator());
		plumbClosedSelected =aIncident.getPlumbIssueClsdIndicator();
		if(plumbClosedSelected.equals("N")){
			plumClosed.setSelection(0);
		}
		else{
			plumClosed.setSelection(1);
			
		}
        plumClosed.setOnItemSelectedListener(new plumbClosedOnItemSelectedListener());

		
		roofIssue=(Spinner)findViewById(R.id.issueRoof);
		Log.d("Update", "roofIssue: "+aIncident.getRoofsIssueIndicator());
		roofIssueSelected =aIncident.getRoofsIssueIndicator();
		if(roofIssueSelected.equals("N")){
			roofIssue.setSelection(0);
		}
		else{
			roofIssue.setSelection(1);
			roofIssue.setEnabled(false);
			
		}
        roofIssue.setOnItemSelectedListener(new roofIssueOnItemSelectedListener());

		
		roofClosed=(Spinner)findViewById(R.id.closedRoof);
		Log.d("Update", "roofClosed: "+aIncident.getRoofsIssueClsdIndicator());
		roofClosedSelected =aIncident.getRoofsIssueClsdIndicator();
		if(roofClosedSelected.equals("N")){
			roofClosed.setSelection(0);
		}
		else{
			roofClosed.setSelection(1);
			
		}
        roofClosed.setOnItemSelectedListener(new roofClosedOnItemSelectedListener());

		
		safeIssue=(Spinner)findViewById(R.id.issueSafe);
		Log.d("update", "safeIssue: "+ aIncident.getSafetyIssueIndicator());
		safetyIssueSelected =aIncident.getSafetyIssueIndicator();
		if(safetyIssueSelected.equals("N")){
			safeIssue.setSelection(0);
		}
		else{
			safeIssue.setSelection(1);
			safeIssue.setEnabled(false);
			
		}
        safeIssue.setOnItemSelectedListener(new safeIssueOnItemSelectedListener());

		
		safeClosed = (Spinner)findViewById(R.id.closedSafe);
		Log.d("Update", "safeClosed: "+aIncident.getSafetyIssueClsdIndicator());
		safetyClosedSelected =aIncident.getSafetyIssueClsdIndicator();
		if(safetyClosedSelected.equals("N")){
			safeClosed.setSelection(0);
		}
		else{
			safeClosed.setSelection(1);
			
		}
        safeClosed.setOnItemSelectedListener(new safeClosedOnItemSelectedListener());

		
		structIssue=(Spinner)findViewById(R.id.issueStruc);
		Log.d("update", "structIssue: "+ aIncident.getStructIssueIndicator());
		structIssueSelected =aIncident.getStructIssueIndicator();
		if(structIssueSelected.equals("N")){
			structIssue.setSelection(0);
		}
		else{
			structIssue.setSelection(1);
			structIssue.setEnabled(false);
			
		}
        structIssue.setOnItemSelectedListener(new structIssueOnItemSelectedListener());

		
		structClosed=(Spinner)findViewById(R.id.closedStruc);
		Log.d("update", "structClosed: "+ aIncident.getStructIssueClsdIndicator());
		structClosedSelected =aIncident.getStructIssueClsdIndicator();
		if(structClosedSelected.equals("N")){
			structClosed.setSelection(0);
		}
		else{
			structClosed.setSelection(1);			
		}
        structClosed.setOnItemSelectedListener(new structClosedOnItemSelectedListener());

		
//Buttons start
		//Add, save, cancel on top
//	    addPictureTop=(Button)findViewById(R.id.AddPictureButtonTop);
//	    addPictureTop.setOnClickListener(new OnClickListener(){
//
//			@Override
//			public void onClick(View v) {
//				// TODO Auto-generated method stub
//				
//			}
//	    	
//	    });
	    saveTop =(Button)findViewById(R.id.SaveButtonTop);
	    saveTop.setOnClickListener(new OnClickListener(){

	    	@Override
			public void onClick(View v) {
				Log.d("DEBUG", "Clicked on update");
	    		//Group 1

	    		//Group 2
				//Group 3
				//Group 4
				String estCapCost = capital.getText().toString();
				Log.d("Incident Object", "estCapCost check 1: "+estCapCost);
				String estExpenseCost = expense.getText().toString();
				Log.d("Incident Object", "estExpenseCost check 1: "+estExpenseCost);
				//Group 5
				//Group 6			
				String assessNotes = assessment.getText().toString();
				Log.d("Incident object", "assessnotes check 1: "+assessNotes);
				String statusNotes = status.getText().toString();
				Log.d("Incident object", "statusNotes check 1: "+statusNotes);
				String compltnDate = compDate.getText().toString();
				Log.d("Incident object", "completiondate check 1: "+compltnDate);
				String incidentNotes = notes.getText().toString();
				Log.d("Incident object", "incidentNotes check 1: "+incidentNotes);

				//Save all the fields to the incident object

				//Group 1


				//Group 2
				updateSpinnerSelection();
				//aIncident.setComPowerIndicator(commercialPowerSelected);
				//Log.d("Incident Object", "commercial power check: "+commercialPowerSelected);
				//aIncident.setOnGeneratorIndicator(onGeneratorSelected);
				//Log.d("Incident Object", "ongenerator: "+onGeneratorSelected);
				//Group 3
				aIncident.setBuildingStatus(buildingStatusSelected);
				Log.d("Incident Object", "buildStat: "+buildingStatusSelected);
				aIncident.setUnOccupiableIndicator(unoccupiableSelected);
				Log.d("Incident Object", "unoccupiable: "+unoccupiableSelected);
				aIncident.setMobCOIndicator(mobCoSelected);
				Log.d("Incident Object", "mobCo: "+mobCoSelected);
				aIncident.setDamageIndicator(damageSelected);
				Log.d("Incident Object", "damage: "+damageSelected);
				//Group 4
				aIncident.setEstCapCost(Integer.parseInt(estCapCost));
				Log.d("Incident Object", "estCapCost check 2: "+estCapCost);
				aIncident.setEstExpenseCost(Integer.parseInt(estExpenseCost));
				Log.d("Incident Object", "estExpenseCost check 2: "+estExpenseCost);
				//Group 5
				aIncident.setElecIssueIndicator(elecIssueSelected);
				Log.d("Incident Object", "elecIssueSelected: "+elecIssueSelected);
				aIncident.setElecIssueClsdIndicator(elecClosedSelected);
				Log.d("Incident Object", "elecIssueSelected: "+elecClosedSelected);
				aIncident.setEnvIssueIndicator(envirIssueSelected);
				Log.d("Incident Object", "envirIssueSelected: "+envirIssueSelected);
				aIncident.setEnvIssueClsdIndicator(envirClosedSelected);
				Log.d("Incident Object", "envirClosedSelected: "+envirClosedSelected);
				aIncident.setFenceGateIssueIndicator(fgIssueSelected);
				Log.d("Incident Object", "envirClosedSelected: "+fgIssueSelected);
				aIncident.setFenceGateIssueClsdIndicator(fgClosedSelected);
				Log.d("Incident Object", "fgIssueClosed: "+fgClosedSelected);
				aIncident.setGenIssueIndicator(genIssueSelected);
				Log.d("Incident Object", "genIssueSelected: "+genIssueSelected);
				aIncident.setGenIssueClsdIndicator(genClosedSelected);
				Log.d("Incident Object", "genClosedSelected: "+genClosedSelected);

				aIncident.setWaterIssueIndicator(waterIssueSelected);
				Log.d("Incident Object", "waterIssueSelected: "+waterIssueSelected);
				aIncident.setWaterIssueClsdIndicator(waterClosedSelected);
				Log.d("Incident Object", "waterClosedSelected: "+waterClosedSelected);
				aIncident.setGroundsIssueIndicator(groundsIssueSelected);
				Log.d("Incident Object", "groundsIssueSelected: "+groundsIssueSelected);
				aIncident.setGroundsIssueClsdIndicator(groundsClosedSelected);
				Log.d("Incident Object", "groundsClosedSelected: "+groundsClosedSelected);
				aIncident.setMechIssueIndicator(mechIssueSelected);
				Log.d("Incident Object", "mechIssueSelected: "+mechIssueSelected);
				aIncident.setMechIssueClsdIndicator(mechClosedSelected);
				Log.d("Incident Object", "mechClosedSelected: "+mechClosedSelected);
				aIncident.setOtherIssueIndicator(otherIssueSelected);
				Log.d("Incident Object", "otherIssueSelected: "+otherIssueSelected);
				aIncident.setOtherIssueClsdIndicator(otherClosedSelected);
				Log.d("Incident Object", "otherClosedSelected: "+otherClosedSelected);
				aIncident.setPlumbIssueIndicator(plumbIssueSelected);
				Log.d("Incident Object", "plumbIssueSelected: "+plumbIssueSelected);
				aIncident.setPlumbIssueClsdIndicator(plumbClosedSelected);
				Log.d("Incident Object", "plumbClosedSelected: "+plumbClosedSelected);
				aIncident.setRoofsIssueIndicator(roofIssueSelected);
				Log.d("Incident Object", "roofIssueSelected: "+roofIssueSelected);
				aIncident.setRoofsIssueClsdIndicator(roofClosedSelected);
				Log.d("Incident Object", "roofClosedSelected: "+roofClosedSelected);
				aIncident.setSafetyIssueIndicator(safetyIssueSelected);
				Log.d("Incident Object", "safetyIssueSelected: "+safetyIssueSelected);
				aIncident.setSafetyIssueClsdIndicator(safetyClosedSelected);
				Log.d("Incident Object", "safetyClosedSelected: "+safetyClosedSelected);
				aIncident.setStructIssueIndicator(structIssueSelected);
				Log.d("Incident Object", "structIssueSelected: "+structIssueSelected);
				aIncident.setStructIssueClsdIndicator(structClosedSelected);
				Log.d("Incident Object", "structClosedSelected: "+structClosedSelected);
				//Group 6
				aIncident.setAssessNotes(assessNotes);
				Log.d("Incident Object", "assessNotes check 2: "+assessNotes);
				aIncident.setStatusNotes(statusNotes);
				Log.d("Incident Object", "statusNotes check 2: "+statusNotes);
				aIncident.setCompltnDate(compltnDate);
				Log.d("Incident Object", "compltnDate check 2: "+compltnDate);
				aIncident.setIncidentNotes(incidentNotes);
				Log.d("Incident Object", "incidentNotes check 2: "+incidentNotes);
				aIncident.setIncidentStatus(reportStatusSelected);
				Log.d("Incident Object", "report status check 2: "+reportStatusSelected);
				
				//Try to add the incident
				try {
					Log.d("DEBUG", "Entered try to update");
					Log.d("Print session", "SessionToken: "+sessionTokenId);

					test.updateIncidentbyRecnum(sessionTokenId, aIncident);
					success.show();
					Intent i = new Intent(getBaseContext(),
							GeolocSearchActivity.class);
					i.putExtra("AUTHORIZATION_TYPE",authorizationType);
					i.putExtra("TOKEN_ID", sessionTokenId);
					i.putExtra("USER_NAME", userNameStr);
		    		startActivity(i);
				} 
				catch(NullPointerException e){
					e.printStackTrace();
				}
				catch (TokenInvalidException e) {
					Log.d("DEBUG", "Entered catch TokenInvalidException");
					fail1.show();
					e.printStackTrace();
				} catch (GeolocInvalidException e) {
					Log.d("DEBUG", "Entered catch GeolocInvalidException");
					fail2.show();
					e.printStackTrace();
				}
			}//end onclick
	    	
	    });
	    cancelTop=(Button)findViewById(R.id.CancelButtonTop);
		cancelTop.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
    		Log.d("AddAssessmentActivity", "Pressed cancel");
    		
    		fail2.show();
			Intent i = new Intent();
			i.setClassName("com.fourGirlsAndADude.mobileDRT", "com.fourGirlsAndADude.mobileDRT.LoginActivity");
			startActivity(i);
			finish();
			}
			
		});
//	    addPictureBottom=(Button)findViewById(R.id.AddPictureButtonBottom);
//	    addPictureBottom.setOnClickListener(new OnClickListener(){
//
//			@Override
//			public void onClick(View arg0) {
//				// TODO Auto-generated method stub
//				
//			}
//	    	
//	    });
	    saveBottom =(Button)findViewById(R.id.SaveButtonBottom);
	    saveBottom.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				Log.d("DEBUG", "Clicked on update");
	    		//Group 1
	
	    		//Group 2
				//Group 3
				//Group 4
				String estCapCost = capital.getText().toString();
				Log.d("Incident Object", "estCapCost check 1: "+estCapCost);
				String estExpenseCost = expense.getText().toString();
				Log.d("Incident Object", "estExpenseCost check 1: "+estExpenseCost);
				//Group 5
				//Group 6			
				String assessNotes = assessment.getText().toString();
				Log.d("Incident object", "assessnotes check 1: "+assessNotes);
				String statusNotes = status.getText().toString();
				Log.d("Incident object", "statusNotes check 1: "+statusNotes);
				String compltnDate = compDate.getText().toString();
				Log.d("Incident object", "completiondate check 1: "+compltnDate);
				String incidentNotes = notes.getText().toString();
				Log.d("Incident object", "incidentNotes check 1: "+incidentNotes);
	
				//Save all the fields to the incident object
	
				//Group 1
	
	
				//Group 2
				updateSpinnerSelection();
				//aIncident.setComPowerIndicator(commercialPowerSelected);
				//Log.d("Incident Object", "commercial power check: "+commercialPowerSelected);
				//aIncident.setOnGeneratorIndicator(onGeneratorSelected);
				//Log.d("Incident Object", "ongenerator: "+onGeneratorSelected);
				//Group 3
				aIncident.setBuildingStatus(buildingStatusSelected);
				Log.d("Incident Object", "buildStat: "+buildingStatusSelected);
				aIncident.setUnOccupiableIndicator(unoccupiableSelected);
				Log.d("Incident Object", "unoccupiable: "+unoccupiableSelected);
				aIncident.setMobCOIndicator(mobCoSelected);
				Log.d("Incident Object", "mobCo: "+mobCoSelected);
				aIncident.setDamageIndicator(damageSelected);
				Log.d("Incident Object", "damage: "+damageSelected);
				//Group 4
				aIncident.setEstCapCost(Integer.parseInt(estCapCost));
				Log.d("Incident Object", "estCapCost check 2: "+estCapCost);
				aIncident.setEstExpenseCost(Integer.parseInt(estExpenseCost));
				Log.d("Incident Object", "estExpenseCost check 2: "+estExpenseCost);
				//Group 5
				aIncident.setElecIssueIndicator(elecIssueSelected);
				Log.d("Incident Object", "elecIssueSelected: "+elecIssueSelected);
				aIncident.setElecIssueClsdIndicator(elecClosedSelected);
				Log.d("Incident Object", "elecIssueSelected: "+elecClosedSelected);
				aIncident.setEnvIssueIndicator(envirIssueSelected);
				Log.d("Incident Object", "envirIssueSelected: "+envirIssueSelected);
				aIncident.setEnvIssueClsdIndicator(envirClosedSelected);
				Log.d("Incident Object", "envirClosedSelected: "+envirClosedSelected);
				aIncident.setFenceGateIssueIndicator(fgIssueSelected);
				Log.d("Incident Object", "envirClosedSelected: "+fgIssueSelected);
				aIncident.setFenceGateIssueClsdIndicator(fgClosedSelected);
				Log.d("Incident Object", "fgIssueClosed: "+fgClosedSelected);
				aIncident.setGenIssueIndicator(genIssueSelected);
				Log.d("Incident Object", "genIssueSelected: "+genIssueSelected);
				aIncident.setGenIssueClsdIndicator(genClosedSelected);
				Log.d("Incident Object", "genClosedSelected: "+genClosedSelected);
	
				aIncident.setWaterIssueIndicator(waterIssueSelected);
				Log.d("Incident Object", "waterIssueSelected: "+waterIssueSelected);
				aIncident.setWaterIssueClsdIndicator(waterClosedSelected);
				Log.d("Incident Object", "waterClosedSelected: "+waterClosedSelected);
				aIncident.setGroundsIssueIndicator(groundsIssueSelected);
				Log.d("Incident Object", "groundsIssueSelected: "+groundsIssueSelected);
				aIncident.setGroundsIssueClsdIndicator(groundsClosedSelected);
				Log.d("Incident Object", "groundsClosedSelected: "+groundsClosedSelected);
				aIncident.setMechIssueIndicator(mechIssueSelected);
				Log.d("Incident Object", "mechIssueSelected: "+mechIssueSelected);
				aIncident.setMechIssueClsdIndicator(mechClosedSelected);
				Log.d("Incident Object", "mechClosedSelected: "+mechClosedSelected);
				aIncident.setOtherIssueIndicator(otherIssueSelected);
				Log.d("Incident Object", "otherIssueSelected: "+otherIssueSelected);
				aIncident.setOtherIssueClsdIndicator(otherClosedSelected);
				Log.d("Incident Object", "otherClosedSelected: "+otherClosedSelected);
				aIncident.setPlumbIssueIndicator(plumbIssueSelected);
				Log.d("Incident Object", "plumbIssueSelected: "+plumbIssueSelected);
				aIncident.setPlumbIssueClsdIndicator(plumbClosedSelected);
				Log.d("Incident Object", "plumbClosedSelected: "+plumbClosedSelected);
				aIncident.setRoofsIssueIndicator(roofIssueSelected);
				Log.d("Incident Object", "roofIssueSelected: "+roofIssueSelected);
				aIncident.setRoofsIssueClsdIndicator(roofClosedSelected);
				Log.d("Incident Object", "roofClosedSelected: "+roofClosedSelected);
				aIncident.setSafetyIssueIndicator(safetyIssueSelected);
				Log.d("Incident Object", "safetyIssueSelected: "+safetyIssueSelected);
				aIncident.setSafetyIssueClsdIndicator(safetyClosedSelected);
				Log.d("Incident Object", "safetyClosedSelected: "+safetyClosedSelected);
				aIncident.setStructIssueIndicator(structIssueSelected);
				Log.d("Incident Object", "structIssueSelected: "+structIssueSelected);
				aIncident.setStructIssueClsdIndicator(structClosedSelected);
				Log.d("Incident Object", "structClosedSelected: "+structClosedSelected);
				//Group 6
				aIncident.setAssessNotes(assessNotes);
				Log.d("Incident Object", "assessNotes check 2: "+assessNotes);
				aIncident.setStatusNotes(statusNotes);
				Log.d("Incident Object", "statusNotes check 2: "+statusNotes);
				aIncident.setCompltnDate(compltnDate);
				Log.d("Incident Object", "compltnDate check 2: "+compltnDate);
				aIncident.setIncidentNotes(incidentNotes);
				Log.d("Incident Object", "incidentNotes check 2: "+incidentNotes);
				aIncident.setIncidentStatus(reportStatusSelected);
				Log.d("Incident Object", "report status check 2: "+reportStatusSelected);
				
				//Try to add the incident
				try {
					Log.d("DEBUG", "Entered try to update");
					Log.d("Print session", "SessionToken: "+sessionTokenId);
	
					test.updateIncidentbyRecnum(sessionTokenId, aIncident);
					success.show();
					Intent i = new Intent(getBaseContext(),
							GeolocSearchActivity.class);
					i.putExtra("AUTHORIZATION_TYPE",authorizationType);
					i.putExtra("TOKEN_ID", sessionTokenId);
					i.putExtra("USER_NAME", userNameStr);
		    		startActivity(i);
				} 
				catch(NullPointerException e){
					e.printStackTrace();
				}
				catch (TokenInvalidException e) {
					Log.d("DEBUG", "Entered catch TokenInvalidException");
					fail1.show();
					e.printStackTrace();
				} catch (GeolocInvalidException e) {
					Log.d("DEBUG", "Entered catch GeolocInvalidException");
					fail2.show();
					e.printStackTrace();
				}
			}//end onclick
	    	
	    });
	    cancelBottom=(Button)findViewById(R.id.CancelButtonBottom);
		cancelBottom.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
			Log.d("AddAssessmentActivity", "Pressed cancel");
    		
    		fail2.show();
			Intent i = new Intent();
			i.setClassName("com.fourGirlsAndADude.mobileDRT", "com.fourGirlsAndADude.mobileDRT.LoginActivity");
			startActivity(i);
			finish();
			}
			
		});
//Buttons end	
	}

//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.update_assement, menu);
//		return true;
//	}
	
	private class ReportOpenOnItemSelectedListener implements
	OnItemSelectedListener {
		
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			reportStatusSelected=(String)arg0.getItemAtPosition(arg2);
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
		}
	}
	private class CommercialPowerOnSelectedItemClickListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			commercialPowerSelected=(String)arg0.getItemAtPosition(arg2);
			
		}

		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
		}
		
	}
	private class onGeneratorOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			onGeneratorSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class DamagedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			damageSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
	}
	private class mobCoOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			mobCoSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class unoccupiableOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			unoccupiableSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class buildingStatusOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			buildingStatusSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	
	private class elecIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			elecIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class elecClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			elecClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class envirIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			envirIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class envirClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			envirClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class fgIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			fgIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class fgClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			fgClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class genIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			genIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class genClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			genClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class waterIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			waterIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class waterClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			waterClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class groundsIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			groundsIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class groundsClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			groundsClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class mechIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			mechIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class mechClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			mechClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class otherIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			otherIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class otherClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			otherClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class plumbIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			plumbIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class plumbClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			plumbClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class roofIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			roofIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class roofClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			roofClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class safeIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			safetyIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class safeClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			safetyClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class structIssueOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			structIssueSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private class structClosedOnItemSelectedListener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			structClosedSelected=(String)arg0.getItemAtPosition(arg2);
			
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
		
	}
	private void updateSpinnerSelection(){
		commercialPower=(Spinner)findViewById(R.id.commercialPower);
		aIncident.setComPowerIndicator(commercialPower.getSelectedItem().toString());
		onGenerator=(Spinner)findViewById(R.id.onGeneratorSpinner);
		aIncident.setOnGeneratorIndicator(onGenerator.getSelectedItem().toString());
		
	}
	
	
}//end of class
